package com.up.cloudfeiyibackend.controller;

import com.up.cloudfeiyibackend.constant.ItemMessageConstant;
import com.up.cloudfeiyibackend.dto.*;
import com.up.cloudfeiyibackend.result.PageResult;
import com.up.cloudfeiyibackend.result.Result;
import com.up.cloudfeiyibackend.service.ItemService;
import com.up.cloudfeiyibackend.vo.*;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 非遗项目相关接口
 */
@RestController
@RequestMapping("/item")
@RequiredArgsConstructor
public class ItemController {

    private final ItemService itemService;

    /**
     * 分页查询所有非遗项目
     *
     * @param itemPageDto
     * @return
     */
    @GetMapping("/pageQuery")
    public Result<PageResult<ItemVO>> pageQuery(ItemPageDto itemPageDto) {
        PageResult<ItemVO> pageResult = itemService.pageQuery(itemPageDto);
        return Result.success(ItemMessageConstant.PAGE_SUCCESS, pageResult);
    }

    /**
     * 查询所有非遗项目分类
     *
     * @return
     */
    @GetMapping("/categories")
    public Result<List<ItemCategoryVO>> listCategories() {
        List<ItemCategoryVO> itemCategoryVOList = itemService.getAllCategories();
        return Result.success(ItemMessageConstant.LIST_CATEGORIES_SUCCESS, itemCategoryVOList);
    }

    /**
     * 查询单个非遗项目详情
     *
     * @param itemId
     * @return
     */
    @GetMapping("/detail/{itemId}")
    public Result<ItemDetailVO> getItemDetail(@PathVariable Long itemId) {
        ItemDetailVO detail = itemService.getDetailByItemId(itemId);
        return Result.success(ItemMessageConstant.GET_DETAIL_SUCCESS, detail);
    }

    /**
     * 查询所有非遗项目地区
     * @return
     */
    @GetMapping("/regions")
    public Result<List<ItemRegionVO>> listRegions() {
        return itemService.listRegions();
    }

    /**
     *
     * 获取该项目传承人信息
     * @param itemId
     * @return
     */
    @GetMapping("/inheritors/{itemId}")
    public Result<List<InheritorVO>> listInheritors(@PathVariable Long itemId) {
        return itemService.listInheritors(itemId);
    }
}
